<?php

namespace app\api\validate;

use think\Validate;

class Opinions extends Validate
{
    /**
     * 验证规则
     */
    protected $rule = [
        'content'   => 'require|regex:\S{6,400}',
        'mobile'    => 'require|regex:^1\d{10}$',
        'username'  => 'require',
        'type_id'   => 'require',
    ];
    /**
     * 提示消息
     */
    protected $message = [
        'type_id.require'       => '请选择类型',
        'username.require' => '联系人不能为空',
        'mobile.require' => '联系方式不能为空',
        'mobile.regex' => '联系方式格式错误',
        'content.regex' => '详细信息包含非法字符或长度不符合要求（6-400个字符）',
        'content.require' => '详细信息不能为空',
    ];
    /**
     * 验证场景
     */
    protected $scene = [
        'add'  => [
            'type_id',
            'username',
            'mobile',
            'content',
        ],
        'edit' => [],
    ];

    public function __construct(array $rules = [], $message = [], $field = [])
    {
        $this->field = [
            'type_id' => __('Type_id'),
            'username' => __('Username'),
            'mobile' => __('Mobile'),
            'content'    => __('Content'),
        ];
        parent::__construct($rules, $message, $field);
    }

}
